package com.wwinsoft.framework.entity.security;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

/**
 * @author: Tim Chen
 * @since 1.0
 */

@Entity
@Table(name = "ACCT_ROLE_AUTHORITY")
@JsonIgnoreProperties(value = { "parent", "hibernateLazyInitializer", "handler" })
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class RoleAuthority {

    private RoleAuthorityPK key;
    private Integer type;

    public RoleAuthority() {
    }

    public RoleAuthority(RoleAuthorityPK key, Integer type) {
        this.key = key;
        this.type = type;
    }

    public RoleAuthority(Long roleId, Long authorityId, Integer type) {
        this.key = new RoleAuthorityPK(roleId, authorityId);
        this.type = type;
    }

    @EmbeddedId
    @GeneratedValue(generator = "AssignedIDGenerator")
    @GenericGenerator(name = "AssignedIDGenerator", strategy = "assigned")
    public RoleAuthorityPK getKey() {
        return key;
    }

    public void setKey(RoleAuthorityPK key) {
        this.key = key;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    @Transient
    public Long getRoleId() {
        return key==null?null:key.getRoleId();
    }

    @Transient
    public Long getAuthorityId() {
        return key==null?null:key.getAuthorityId();
    }

}
